# 比较两个文件不同

import os

def get_prefixes(folder_path):
    """从指定文件夹中提取所有文件的前缀"""
    prefixes = set()
    files = os.listdir(folder_path)
    total_files = len(files)
    print(f"处理文件夹 {folder_path} 中...")

    for i, filename in enumerate(files, 1):
        prefix = filename.split('_')[0]
        prefixes.add(prefix)
        # 每处理10个文件，打印一次进度
        if i % 10 == 0 or i == total_files:
            print(f"处理进度: {i}/{total_files} 文件完成")

    return prefixes

# 设置两个文件夹的路径
folder1 = 'F:/Dataset/voc-for-yolo/images/val'
folder2 = 'F:/Dataset/voc-for-yolo/labels/val'

# 获取两个文件夹的前缀集合
prefixes1 = get_prefixes(folder1)
prefixes2 = get_prefixes(folder2)

# 计算两个文件夹独有的前缀
unique_prefixes_folder1 = prefixes1 - prefixes2
unique_prefixes_folder2 = prefixes2 - prefixes1

# 打印结果
print(f"\nUnique prefixes in '{folder1}':")
for prefix in unique_prefixes_folder1:
    print(prefix)

print(f"\nUnique prefixes in '{folder2}':")
for prefix in unique_prefixes_folder2:
    print(prefix)
